package com.jing.ads.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.jing.ads.R;
import com.jing.ads.model.PushAppInfo.AppDetail;
import com.jing.ads.util.GlobalUtil;
import com.jing.ads.util.NotificationUtil;

public class AppReceiver extends BroadcastReceiver {
	public static final String ACTION_NET_CHANGE = "android.net.conn.CONNECTIVITY_CHANGE";
	public static final String ACTION_BOOT = "android.intent.action.BOOT_COMPLETED";
	public static final String ACTION_LAUNCHER = "com.jing.ads.launcher";

	@Override
	public void onReceive(final Context context, Intent intent) {
		String action = intent.getAction();
		if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
			String packageName = intent.getDataString();
			if (packageName.contains(":")) {
				packageName = packageName.substring(8);
			}
			AppDetail app = new AppDetail();
			app.packageName = packageName;
			GlobalUtil.setAppDownloadStatus(context.getContentResolver(), app);
			if (app.downloadStatus == AppDetail.DOWNLOADED) {
				String content = context.getString(R.string.notify_active, app.appName);
				NotificationUtil.getInstance(context).showNotify(app.appName, content, packageName, false);
			}
		} else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
//			String packageName = intent.getDataString();
		}
	}
}
